# 环境配置，启动ui界面
import os

def prepare_environment():
    # 安装环境
    diffusers_auto_update()


def diffusers_auto_update():
    try:
        import ppgan, paddlespeech, paddleaudio,typeguard
        from PaddleTools.GAN import FOM
        from PaddleTools.TTS import TTSExecutor
        from PaddleTools.GAN import wav2lip
        if not (paddlespeech.__version__ == "1.0.0"
                and paddleaudio.__version__ == "1.0.1"
                and typeguard.__version__ == "2.13.2"):
            raise ImportError
        print("environment all ready!")

    except (ModuleNotFoundError, ImportError, AttributeError):
        print('检测到库不完整或版本不正确, 正在安装库')
        os.system("pip install ppgan --user")
        os.system("pip install paddlespeech==1.0.0 --user")
        os.system("pip install paddleaudio==1.0.1 --user")
        os.system("pip install typeguard==2.13.2 --user")

def start():
    import webui
    webui.shuziren2D.launch(share=True) 

if __name__ == "__main__":
    prepare_environment()
    start()
